﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UtilsExtensionsAndHelpers.Utils;
using UtilsExtensionsAndHelpers.Utils.Implimentations;

namespace UtilsExtensionsAndHelpers.Demo
{
    #region Test Classes
    public interface IDashboardRepository
    {
        string GetMessage();
    }
    public class DashboardRepository: IDashboardRepository {
        public string GetMessage()
        {
            return "Dependency Injection was successful.";
        }
    }
    public interface IController
    {
        string GetMessage();
    }
    public interface IDashboardController : IController {}

    public class DashboardController: IDashboardController
    {
        private IDashboardRepository _dashboardRepository;

        public DashboardController(IDashboardRepository dashboardRepository)
        {
            _dashboardRepository = dashboardRepository;
        }

        public string GetMessage()
        {
            return _dashboardRepository.GetMessage();
        }
    }
    #endregion

    class Program
    {
        
        static void Main(string[] args)
        {
            var type = Type.GetType("UtilsExtensionsAndHelpers.Demo.IDashboardController");
            var c = ObjectFactory.Instance<IController>(type);
            var msg = c.GetMessage();

            Console.WriteLine(msg);
            Console.ReadLine();
        }

        private static IObjectFactory _objectFactory;
        protected static IObjectFactory ObjectFactory
        {
            get { return _objectFactory ?? (_objectFactory = LoadObjectFactory()); }
        }
        private static IObjectFactory LoadObjectFactory()
        {
            var o = new ObjectFactory();

            o.Bind<IDashboardRepository>(() => new DashboardRepository());
            o.Bind<IDashboardController>(() => {
                var repo = o.Instance<IDashboardRepository>();
                return new DashboardController(repo);
            });

            return o;
        }
    }
}
